package com.idconfirmsystem.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.idconfirmsystem.R;
import com.idconfirmsystem.adapter.TaskAdapter.ViewHolder;
import com.idconfirmsystem.model.Bag;

public class BagAdapter extends BaseAdapter {
	private List<Bag> bagList = new ArrayList<Bag>();
	private Context context;
	private ListView listView;
	private Bag bag;

	public BagAdapter(Context context, ListView listView) {
		this.context = context;
		this.listView = listView;
	}

	public BagAdapter(Context context, ListView listView, List<Bag> bagList) {
		this.context = context;
		this.listView = listView;
		this.bagList = bagList;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return bagList.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return bagList.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		final ViewHolder viewHolder;
		if (convertView == null) {
			convertView = View.inflate(context, R.layout.item_bag, null);
			viewHolder = new ViewHolder();
			viewHolder.tv_arrival_time = (TextView) convertView.findViewById(R.id.tv_arrival_time);
			viewHolder.tvBag = (TextView) convertView.findViewById(R.id.tv_bagInfo);
			viewHolder.tvBank_name = (TextView) convertView.findViewById(R.id.tv_bank_name);
			viewHolder.tvBank_num = (TextView) convertView.findViewById(R.id.tv_bank_num);

			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		bag = bagList.get(position);
		viewHolder.tv_arrival_time.setText(bag.getArrival_time().toLocaleString());
		viewHolder.tvBag.setText(bag.getBags_number() + " " + bag.getBags_seal_no());
		viewHolder.tvBank_name.setText(bag.getBranch_name());
		viewHolder.tvBank_num.setText(bag.getBranch_number());

		return convertView;
	}

	public class ViewHolder {
		public TextView tvBag;
		public TextView tvBank_num;
		public TextView tvBank_name;
		public TextView tv_arrival_time;
	}
}
